package com.ibangnuo.manage.controller.commercial;

import com.ibangnuo.api.commercial.CommercialControllerApi;
import com.ibangnuo.framework.domain.Channel;
import com.ibangnuo.framework.domain.CommercialTenant;
import com.ibangnuo.framework.domain.ext.CommercialTenantExt;
import com.ibangnuo.framework.domain.ext.CommercialTenantNewExt;
import com.ibangnuo.framework.domain.request.commercial.CommercialTenantNewRequest;
import com.ibangnuo.framework.domain.request.commercial.CommercialTenantRequest;
import com.ibangnuo.framework.model.response.ObjectResult;
import com.ibangnuo.framework.model.response.QueryResponseResult;
import com.ibangnuo.framework.model.response.ResponseResult;
import com.ibangnuo.manage.service.commercial.CommercialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author: wwy
 * @Date: 2019-12-30 11:16
 */
@RestController
@RequestMapping("/commercial")
public class CommercialController implements CommercialControllerApi {
    @Autowired
    private CommercialService commercialService;

    /**
     * 新增商户
     *
     * @param commercialTenantExt
     * @return
     */
    @PostMapping("/add")
    @Override
    public ResponseResult add(@RequestBody CommercialTenantExt commercialTenantExt) {
        return commercialService.add(commercialTenantExt);
    }

    /**
     * 通道申请
     *
     * @param
     * @return
     */
    @Override
    @PostMapping("/channel")
    public ResponseResult Channel(@RequestBody Channel channel) {

        return commercialService.Channel(channel);
    }

    /**
     * 通道申请
     *
     * @param
     * @return
     */
    @Override
    @PostMapping("/findByIdAndType/{commercialId}")
    public QueryResponseResult EditChannel(@PathVariable("commercialId") String commerciaId ) {

        return commercialService.EditChannel(commerciaId);
    }

    /**
     * 分页条件查询
     *
     * @param commercialTenantRequest
     * @return
     */
    @PostMapping("/list")
    @Override
    public QueryResponseResult findList(@RequestBody CommercialTenantRequest commercialTenantRequest) {
        return commercialService.findList(commercialTenantRequest);
    }

    /**
     * 根据id查找
     *
     * @param id
     * @return
     */
    @GetMapping("/findById/{id}")
    @Override
    public ObjectResult findById(@PathVariable("id") String id) {
        return commercialService.findById(id);
    }

    /**
     * 根据id更新
     *
     * @param id
     * @param commercialTenantExt
     * @return
     */
    @PostMapping("/update/{id}")
    @Override
    public ResponseResult update(@PathVariable("id") String id, @RequestBody CommercialTenantExt commercialTenantExt) {
        return commercialService.update(id, commercialTenantExt);
    }

    /**
     * 根据id删除
     *
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    @Override
    public ResponseResult delete(@PathVariable("id") String id) {
        return commercialService.delete(id);
    }

    /**
     * 根据主键修改图片资源
     *
     * @param id
     * @param map
     * @return
     */
    @PostMapping("/updateImage/{id}")
    @Override
    public ResponseResult updateImage(@PathVariable("id") String id, @RequestBody Map<String, Object> map) {
        return commercialService.updateImage(id, map);
    }

    /**
     * 查询所有商户的名字
     *
     * @return
     */
    @Override
    @GetMapping("/name")
    public QueryResponseResult selectAllName() {

        return commercialService.selectAllName();
    }

    /**
     * 不映射查询全部新
     *
     * @return
     */
    @PostMapping("/findAllNew/{page}/{size}")
    @Override
    public QueryResponseResult findByCommercialAndCommercialDetails(@PathVariable("page") int page, @PathVariable("size") int size, @RequestBody CommercialTenantNewRequest commercialTenantNewRequest) {
        return commercialService.findByCommercialAndCommercialDetails(page, size, commercialTenantNewRequest);
    }

    /**
     * 查询图片map格式
     *
     * @param id
     * @return
     */
    @GetMapping("/findImgById/{id}")
    @Override
    public ObjectResult findImgById(@PathVariable("id") String id) {
        return commercialService.findImgById(id);
    }

    /**
     * 根据代理商id查询商户
     * @param id
     * @return
     */
    @GetMapping("/findByAgentId/{id}")
    @Override
    public ObjectResult findByAgentId(@PathVariable("id") String id) {
        return commercialService.findByAgentId(id);
    }

    /**
     * 统计商户
     * @return
     */
    @GetMapping("/findCommercialCount")
    @Override
    public ObjectResult findCommercialCount() {
        return commercialService.findCommercialCount();
    }

    /**
     * 批量删除商户
     * @param ids
     * @return
     */
    @PostMapping("/deleteListById")
    @Override
    public ResponseResult deleteListById(@RequestBody List<String> ids) {
        return commercialService.deleteListById(ids);
    }


    /**
     * 新版增加商户
     *
     * @param commercialTenantNewExt
     * @return
     */
    @PostMapping("/addNew")
    @Override
    public ObjectResult addNew(@RequestBody CommercialTenantNewExt commercialTenantNewExt) {
        return commercialService.addNew(commercialTenantNewExt);
    }

    /**
     * 新版获取商户信息
     *
     * @param id
     * @return
     */
    @GetMapping("/findByIdNew/{id}")
    @Override
    public ObjectResult findByIdNew(@PathVariable("id") String id) {
        return commercialService.findByIdNew(id);
    }


}
